/*
 * @Author: Du Weixing duweixing@sgsimulation.com
 * @Date: 2024-10-20 21:40:04
 * @LastEditors: Du Weixing duweixing@sgsimulation.com
 * @LastEditTime: 2024-10-21 01:48:40
 * @FilePath: \SGFEM\Solver\SectionCalculator\BeamSection\FormulaMethod\test\LBeamSectionFormulaCalculatorTest.hpp
 * @Description: 
 * 
 * Copyright (c) 2024 by 神工仿真, All Rights Reserved. 
 */

#pragma once
#include "gtest/gtest.h"
#include "DataStructure/Common/Real.h"
#include "DataStructure/Input/Property/BeamSectionStandardTypes.h"
#include "../Interface/BeamSectionFormulaCalculatorFactory.h"
#include "../Beam/LBeamSectionFormulaCalculator.h"

using SG::DataStructure::Common::Real;
using namespace SG::DataStructure::FEM;
using SG::FEMSolver::Element::BeamSectionFormulaCalculatorFactory;
using SG::FEMSolver::Element::LBeamSectionFormulaCalculator;

// 将 BeamSectionFormulaCalculatorFactory 生成对象测试放置在具体截面属性计算中
TEST (BeamSectionFormulaCalculatorFactoryTest, LSectionCalculatorCreate)
{
    // Test data
    auto calculatorPtr = BeamSectionFormulaCalculatorFactory::Create (BeamSectionStandardTypes::BEAMSECTYPE_L);
    auto LCalculatorPtr = dynamic_cast<LBeamSectionFormulaCalculator*> (calculatorPtr.get ());

    // Check
    ASSERT_TRUE (nullptr != LCalculatorPtr);
}

// PBEAML-L 恒截面属性计算测试
TEST (BeamSectionFormulaCalculatorTest, LSection)
{
    // Input data
    PBEAMLData pBeamL;
    pBeamL.m_id  = 2;
    pBeamL.m_mId = 3;
    pBeamL.SetGroup ("MSCBML0");
    pBeamL.SetBeamSectionStandardTypes (BeamSectionStandardTypes::BEAMSECTYPE_L);
    pBeamL.m_section = {{1.0, 0.0, 10.0, {3.0, 6.0, 2.5, 1.0}}, {1.0, 1.0, 10.0, {3.0, 6.0, 2.5, 1.0}}};

    // Test data
    LBeamSectionFormulaCalculator calculator;
    auto pBeamTest = calculator.Compute (pBeamL);

    // Target data
    PBEAMData pBeamTarget;
    pBeamTarget.m_id    = 2;
    pBeamTarget.m_mId   = 3;
    pBeamTarget.m_nsges = 1;
    pBeamTarget.m_ccf   = 1;

    Real SO[11] { 1.000000, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,  1.000000};
    Real XXB[11]{ 0.000000, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,  1.000000};
    Real A[11]  { 11.00000, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,  11.00000};
    Real I1[11] { 28.95644, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,  28.95644};
    Real I2[11] { 8.303030, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,  8.303030};
    Real I12[11]{-7.159091, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -7.159091};
    Real J[11]  { 14.60417, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,  14.60417};
    Real NSM[11]{ 10.00000, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,  10.00000};
    std::memcpy (pBeamTarget.m_SO,  SO,  sizeof (SO));
    std::memcpy (pBeamTarget.m_XXB, XXB, sizeof (XXB));
    std::memcpy (pBeamTarget.m_A,   A,   sizeof (A));
    std::memcpy (pBeamTarget.m_I1,  I1,  sizeof (I1));
    std::memcpy (pBeamTarget.m_I2,  I2,  sizeof (I2));
    std::memcpy (pBeamTarget.m_I12, I12, sizeof (I12));
    std::memcpy (pBeamTarget.m_J,   J,   sizeof (J));
    std::memcpy (pBeamTarget.m_NSM, NSM, sizeof (NSM));

    Real C1[11]{ 4.75, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,  4.75};
    Real C2[11]{ 0.50, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,  0.50};
    Real D1[11]{-1.25, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -1.25};
    Real D2[11]{ 2.50, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,  2.50};
    Real E1[11]{-1.25, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -1.25};
    Real E2[11]{-0.50, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -0.50};
    Real F1[11]{ 4.75, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,  4.75};
    Real F2[11]{-0.50, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -0.50};
    std::memcpy (pBeamTarget.m_C1, C1, sizeof (C1));
    std::memcpy (pBeamTarget.m_C2, C2, sizeof (C2));
    std::memcpy (pBeamTarget.m_D1, D1, sizeof (D1));
    std::memcpy (pBeamTarget.m_D2, D2, sizeof (D2));
    std::memcpy (pBeamTarget.m_E1, E1, sizeof (E1));
    std::memcpy (pBeamTarget.m_E2, E2, sizeof (E2));
    std::memcpy (pBeamTarget.m_F1, F1, sizeof (F1));
    std::memcpy (pBeamTarget.m_F2, F2, sizeof (F2));

    pBeamTarget.m_K1  = 0.3181818;
    pBeamTarget.m_K2  = 0.4545455;
    pBeamTarget.m_CWA = 0.0; // ToDo(9.758681)
    pBeamTarget.m_CWB = 0.0; // ToDo(9.758681)

    pBeamTarget.m_N1A = 0.9545455;
    pBeamTarget.m_N2A = 0.6818182;
    pBeamTarget.m_N1B = 0.9545455;
    pBeamTarget.m_N2B = 0.6818182;

    // Check
    ASSERT_TRUE (pBeamTarget == pBeamTest);
}